import 'package:color_dart/RgbaColor.dart';
import 'package:flutter/material.dart';
import 'package:im_flutter_sdk_example/components/back_btn.dart';
import 'package:im_flutter_sdk_example/components/empty_list.dart';
import 'package:im_flutter_sdk_example/jsonserialize/message/data.dart';
import 'package:im_flutter_sdk_example/provider/group_message.dart';
import 'package:im_flutter_sdk_example/utils/global.dart';
import 'package:provider/provider.dart';

/*
 *@功能: 首页 小组通知
 *@author: lovecrosszhu
 *@date: 2021-02-03 13:56:50
 *@version: V1.0.0
*/

class HomeGroupMessage extends StatefulWidget {
  @override
  _HomeGroupMessageState createState() => _HomeGroupMessageState();
}

class _HomeGroupMessageState extends State<HomeGroupMessage> {
  @override
  void initState() {
    super.initState();
    Future.delayed(Duration.zero, () {
      _loadMessages();
    });
  }

  _loadMessages() {
    GroupMessageProvider groupProvider =
        Provider.of<GroupMessageProvider>(context);
    groupProvider.loadMessage();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(body: _buildContent());
  }

  Widget _buildContent() {
    GroupMessageProvider groupProvider =
        Provider.of<GroupMessageProvider>(context);
    Message message = groupProvider.latestMessage;
    if (message == null) return G.emptyBox();
    return Container(
      width: G.screenWidth(),
      height: G.screenHeight(),
      decoration: BoxDecoration(
        gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [
              rgba(233, 242, 254, 1),
              rgba(246, 250, 255, 0),
            ]),
      ),
      padding: EdgeInsets.fromLTRB(20, 40, 20, 20),
      child: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            BackBtn(),
            SizedBox(
                height: 36,
                child: Image.asset('lib/assets/images/label/groupe_notice.png',
                    fit: BoxFit.contain)),
            Padding(
              padding: const EdgeInsets.only(top: 20),
              child: Text(
                '${message.note}',
                strutStyle: StrutStyle(forceStrutHeight: true, height: 2.5),
                style: TextStyle(
                  fontSize: 16,
                  color: rgba(34, 43, 69, 1),
                  letterSpacing: 2,
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
